package com.hulk.dryad.manage.boot.basic.launch;

import net.dreamlu.mica.core.utils.Once;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;

/**
 * 只执行一次的 EnvironmentPostProcessor
 *
 * @author hulk
 */
public abstract class AbstractOnceLaunch implements EnvironmentPostProcessor, Ordered {
	private final Once once = new Once();

	@Override
	public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
		once.run(this::run, environment, application);
	}

	/**
	 * 执行
	 *
	 * @param environment ConfigurableEnvironment
	 * @param application SpringApplication
	 */
	public abstract void run(ConfigurableEnvironment environment, SpringApplication application);

	@Override
	public int getOrder() {
		return Ordered.LOWEST_PRECEDENCE - 100;
	}

}
